home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / program / scrnmdcl.lha / ScreenModeClass10 / ScreenModeClassTest.c < prev    next >
C/C++ Source or Header  |  1995-09-17  |  12KB  |  278 lines

  1. #include <proto/exec.h>
  2. #include <proto/asl.h>
  3. #include <proto/intuition.h>
  4. #include <clib/alib_protos.h>
  5. #include <proto/bgui.h>
  6. #include <proto/utility.h>
  7. #include <libraries/bgui_macros.h>
  8. #include "LibPerso:Boopsi/ScreenModeClass.h"
  9. #include <stdio.h>
  10.  
  11. #ifdef _DCC
  12. #include <lib/misc.h>
  13. #endif
  14.  
  15. /*
  16. **  Define ID of gadgets
  17. **/
  18. #define GD_BUTTON           0
  19. #define GD_GUI_MODE         1
  20. #define GD_INFO_WIN         2
  21. #define GD_CONTROL_MINSIZE  3
  22. #define GD_DO_WIDTH         4
  23. #define GD_DO_HEIGHT        5
  24. #define GD_DO_OVERSCAN      6
  25. #define GD_DO_AUTOSCROLL    7
  26. #define GD_SLEEP            8
  27. #define GD_MIN_WIDTH        9
  28. #define GD_MIN_HEIGHT       10
  29.  
  30. #define GAD_CNT             11
  31.  
  32.  
  33. /*
  34. **  Datas for the bgui window.
  35. **/
  36. Object          *WO_Main;
  37. struct Window   *MainWnd = NULL;
  38. ULONG           MainMask=NULL;
  39. Object          *MainGad[ GAD_CNT ];
  40.  
  41.  
  42. struct Library  *BGUIBase=NULL;
  43.  
  44. /*
  45. **  Special version of GetAttr.
  46. **/
  47. ULONG GetAttrs( Object *obj, ULONG tag1, ... )
  48. {
  49. struct TagItem          *tstate = ( struct TagItem * )&tag1, *tag;
  50. ULONG                    num = 0L;
  51.  
  52.         while ( tag = NextTagItem( &tstate ))
  53.                 num += GetAttr( tag->ti_Tag, obj, ( ULONG * )tag->ti_Data );
  54.  
  55.         return( num );
  56. }
  57.  
  58.  
  59.  
  60.  
  61. main( int argc, char **argv )
  62. {
  63. Class   *ScreenModeClass=NULL;
  64. Object  *ScreenRequester=NULL;
  65. ULONG   t;
  66. BOOL    done=TRUE;
  67. int     rc;
  68. ULONG   Width, Height, Depth, ModeID, AutoScroll, Overscan;
  69.  
  70.     /*
  71.     **      Open the bgui.library
  72.     **/
  73.     if( !( BGUIBase = OpenLibrary( "bgui.library", 37 ) ))
  74.     {
  75.         printf("This demo use the bgui.library.\n");
  76.         return( 30 );
  77.     }
  78.  
  79.     /*
  80.     **      Init. the class.
  81.     **/
  82.     ScreenModeClass=InitScreenModeClass();
  83.  
  84.     if( ScreenModeClass )
  85.     {
  86.  
  87.         /*
  88.         **  Create a window.
  89.         **/
  90.         WO_Main = WindowObject,
  91.                     WINDOW_Title,           "ScreenMode class demo",
  92.                     WINDOW_RMBTrap,         TRUE,
  93.                     WINDOW_SmartRefresh,    TRUE,
  94.                     WINDOW_ScaleWidth,      20,
  95.                     WINDOW_AutoAspect,      TRUE,
  96.                     WINDOW_LockHeight,      TRUE,
  97.                     WINDOW_MasterGroup,
  98.  
  99.                     VGroupObject, VOffset( 2 ), HOffset( 4 ), Spacing( 2 ),
  100.  
  101.                     /*
  102.                     **  Tags...
  103.                     **/
  104.                     StartMember, HGroupObject, NeXTFrame, FrameTitle( "Tags.."), VOffset( 2 ), BOffset( 4 ), HOffset( 4+4 ), Spacing( 2 ), EqualWidth,
  105.                         StartMember, VGroupObject, Spacing( 4 ),
  106.                             StartMember, MainGad[ GD_GUI_MODE ] = CheckBox( "GUI MODE", 0, GD_GUI_MODE ), FixMinWidth, EndMember,
  107.                             StartMember, MainGad[ GD_INFO_WIN ] = CheckBox( "Info window", 0, GD_INFO_WIN ), FixMinWidth, EndMember,
  108.                             StartMember, MainGad[ GD_CONTROL_MINSIZE ] = CheckBox( "SMC_ControlMinSize", 0, GD_CONTROL_MINSIZE ), FixMinWidth, EndMember,
  109.                             StartMember, MainGad[ GD_SLEEP ] = CheckBox( "Sleep window", 0, GD_SLEEP ), FixMinWidth, EndMember,
  110.                             StartMember, MainGad[ GD_MIN_WIDTH ] = Integer("Min Width", 0, 3, GD_MIN_WIDTH ), NoAlign, FixMinHeight, EndMember,
  111.                         EndObject, FixMinWidth, EndMember,
  112.  
  113.                         VarSpace(1),
  114.  
  115.                         StartMember, VGroupObject, Spacing( 4 ),
  116.                             StartMember, MainGad[ GD_DO_WIDTH ] = CheckBox( "Do Width", 0, GD_DO_WIDTH ), FixMinWidth, EndMember,
  117.                             StartMember, MainGad[ GD_DO_HEIGHT ] = CheckBox( "Do Height", 0, GD_DO_HEIGHT ), FixMinWidth, EndMember,
  118.                             StartMember, MainGad[ GD_DO_OVERSCAN ] = CheckBox( "Do Overscan", 0, GD_DO_OVERSCAN ), FixMinWidth, EndMember,
  119.                             StartMember, MainGad[ GD_DO_AUTOSCROLL ] = CheckBox( "Do AutoScroll", 0, GD_DO_AUTOSCROLL ), FixMinWidth, EndMember,
  120.                             StartMember, MainGad[ GD_MIN_HEIGHT ] = Integer("Min Height", 0, 3, GD_MIN_HEIGHT ), NoAlign, FixMinHeight, EndMember,
  121.                         EndObject, FixMinWidth, EndMember,
  122.  
  123.                     EndObject, FixMinHeight, EndMember,         /* End of TAG group */
  124.  
  125.                     StartMember, MainGad[ GD_BUTTON ] = Button( "Screen mode requester", GD_BUTTON ), FixMinHeight, EndMember,
  126.  
  127.                     EndObject,          /* End of Main VGroup object */
  128.  
  129.                     EndObject;          /* End of WindowObject */
  130.  
  131.  
  132.  
  133.  
  134.  
  135.         if( WO_Main )
  136.         {
  137.             /*
  138.             **  Open a window.
  139.             **/
  140.             MainWnd = WindowOpen( WO_Main );
  141.             GetAttr( WINDOW_SigMask, WO_Main, &MainMask );
  142.  
  143.             /*
  144.             **  Create a ScreenMode object.
  145.             **/
  146.             ScreenRequester=NewObject( ScreenModeClass, NULL,
  147.                         SMC_InitialInfoPos,         SMC_INFOPOS_TopRight,
  148.                         SMC_InfoPosArround,         TRUE,
  149.                         ASLSM_Window,               MainWnd,
  150.                         TAG_END );
  151.         }
  152.  
  153.         if( MainWnd && ScreenRequester )
  154.         do{
  155.             Wait( MainMask );
  156.  
  157.             while (( rc = HandleEvent( WO_Main )) != WMHI_NOMORE )
  158.             {
  159.                 switch ( rc )
  160.                 {
  161.                     case WMHI_CLOSEWINDOW:      done = FALSE;
  162.                                                 break;
  163.  
  164.                     /*
  165.                     **      Tags to set or unset.
  166.                     **/
  167.                     case GD_GUI_MODE:           if( ((struct Gadget *)MainGad[ rc ])->Flags & GFLG_SELECTED )
  168.                                                     SetAttrs( ScreenRequester, SMC_GUI_MODES, TRUE, TAG_END );
  169.                                                 else
  170.                                                     SetAttrs( ScreenRequester, SMC_GUI_MODES, FALSE, TAG_END );
  171.                                                 break;
  172.  
  173.                     case GD_INFO_WIN:           if( ((struct Gadget *)MainGad[ rc ])->Flags & GFLG_SELECTED )
  174.                                                     SetAttrs( ScreenRequester, ASLSM_InitialInfoOpened, TRUE, TAG_END );
  175.                                                 else
  176.                                                     SetAttrs( ScreenRequester, ASLSM_InitialInfoOpened, FALSE, TAG_END );
  177.                                                 break;
  178.  
  179.                     case GD_CONTROL_MINSIZE:    if( ((struct Gadget *)MainGad[ rc ])->Flags & GFLG_SELECTED )
  180.                                                     SetAttrs( ScreenRequester, SMC_ControlMinSize ,TRUE, TAG_END );
  181.                                                 else
  182.                                                     SetAttrs( ScreenRequester, SMC_ControlMinSize, FALSE, TAG_END );
  183.                                                 break;   
  184.  
  185.                     case GD_DO_WIDTH:           if( ((struct Gadget *)MainGad[ rc ])->Flags & GFLG_SELECTED )
  186.                                                     SetAttrs( ScreenRequester, ASLSM_DoWidth, TRUE, TAG_END );
  187.                                                 else
  188.                                                     SetAttrs( ScreenRequester, ASLSM_DoWidth, FALSE, TAG_END );
  189.                                                 break;
  190.  
  191.                     case GD_DO_HEIGHT:          if( ((struct Gadget *)MainGad[ rc ])->Flags & GFLG_SELECTED )
  192.                                                     SetAttrs( ScreenRequester, ASLSM_DoHeight, TRUE, TAG_END );
  193.                                                 else
  194.                                                     SetAttrs( ScreenRequester, ASLSM_DoHeight, FALSE, TAG_END );
  195.                                                 break;
  196.  
  197.                     case GD_DO_OVERSCAN:        if( ((struct Gadget *)MainGad[ rc ])->Flags & GFLG_SELECTED )
  198.                                                     SetAttrs( ScreenRequester, ASLSM_DoOverscanType,TRUE, TAG_END );
  199.                                                 else
  200.                                                     SetAttrs( ScreenRequester, ASLSM_DoOverscanType, FALSE, TAG_END );
  201.                                                 break;
  202.  
  203.                     case GD_DO_AUTOSCROLL:      if( ((struct Gadget *)MainGad[ rc ])->Flags & GFLG_SELECTED )
  204.                                                     SetAttrs( ScreenRequester, ASLSM_DoAutoScroll,TRUE, TAG_END );
  205.                                                 else
  206.                                                     SetAttrs( ScreenRequester, ASLSM_DoAutoScroll, FALSE, TAG_END );
  207.                                                 break;
  208.  
  209.                     case GD_SLEEP:              if( ((struct Gadget *)MainGad[ rc ])->Flags & GFLG_SELECTED )
  210.                                                     SetAttrs( ScreenRequester, ASLSM_SleepWindow,TRUE, TAG_END );
  211.                                                 else
  212.                                                     SetAttrs( ScreenRequester, ASLSM_SleepWindow, FALSE, TAG_END );
  213.                                                 break;
  214.  
  215.                     case GD_MIN_WIDTH:          GetAttr( STRINGA_LongVal, MainGad[ rc ], &t );
  216.                                                 SetAttrs( ScreenRequester, ASLSM_MinWidth, t, TAG_END );
  217.                                                 break;
  218.  
  219.                     case GD_MIN_HEIGHT:         GetAttr( STRINGA_LongVal, MainGad[ rc ], &t );
  220.                                                 SetAttrs( ScreenRequester, ASLSM_MinHeight, t, TAG_END );
  221.                                                 break;
  222.  
  223.                     /*
  224.                     **  Popup the screen mode requester.
  225.                     **/
  226.                     case GD_BUTTON:             if( ScreenModeReq( ScreenRequester ) )
  227.                                                 {
  228.                                                     GetAttrs( ScreenRequester,
  229.                                                                 SMC_DisplayWidth,   &Width,
  230.                                                                 SMC_DisplayHeight,  &Height,
  231.                                                                 SMC_DisplayID,      &ModeID,
  232.                                                                 SMC_AutoScroll,     &AutoScroll,
  233.                                                                 SMC_OverscanType,   &Overscan,
  234.                                                                 SMC_DisplayDepth,   &Depth,
  235.                                                                 TAG_END );
  236.  
  237.                                                     printf("\nModeID= 0x%x\nSize= %d x %d x %d\nAutoScroll=  %s\nOverscanType= %d\n",
  238.                                                                 ModeID, Width, Height, Depth,
  239.                                                                 AutoScroll ? "TRUE":"FALSE",
  240.                                                                 Overscan );
  241.                                                 }
  242.                                                 break;
  243.                 }
  244.             }
  245.  
  246.         } while( done );
  247.  
  248.         /*
  249.         **      Close and dispose the window.
  250.         **/
  251.         if( WO_Main )
  252.             DisposeObject( WO_Main );
  253.  
  254.         /*
  255.         **      Dispose the ScreenMode object.
  256.         **/
  257.         DisposeObject( ScreenRequester );
  258.  
  259.         /*
  260.         **      Dispose the class.
  261.         **/
  262.         FreeScreenModeClass( ScreenModeClass );
  263.     }
  264.  
  265.     CloseLibrary( BGUIBase );
  266.  
  267.     return(0);
  268. }
  269.  
  270.  
  271. #ifdef _DCC
  272. int wbmain( struct WBStartup *w )
  273. {
  274.     OpenConsole( "CON:0/450//100/ScreenModeClass demo/AUTO" );
  275.     return( main( 0, NULL ) );
  276. }
  277. #endif
  278.